{extend name="layout/layout" /}

{block name="pagecss"}

{/block}

{block name="content"}
<div class="row">
	<div class="col-xs-12">
		<div class="box box-success">
			<div class="box-header with-border">
				<h3 class="box-title">设置订单商品的配送方式和运费，并根据买家增加商品而追加运费</h3>
				<div class="box-tools">
					<!--<button class="btn bg-navy btn-sm" data-toggle="tooltip" title="" data-original-title="Back" onclick="history.go(-1);">
                        <i class="fa fa-reply"></i> 返回
                    </button>-->
				</div>
			</div>
			<div class="box-body">
				<div id="modal_new_role" class="form-horizontal form" method="post" enctype="multipart/form-data">
					{:token()}
					<div class="form-body">
						<div class="box-content col-md-8  table-bordered table" style="padding: 25px">
							<div style="float: left">
								<img class="margin-right" src="__STATIC__/admin/img/u5339.png">
							</div>
							<div style="margin-left: 100px">
								<p style="font-size: 18px">物流配送</p>
								<p> 由第三方快递公司或商家完成商品配送服务</p>
							</div>
						</div>
						<!--<div class="box-content col-md-8  table-bordered table" style="padding: 20px">-->
                            <!--<span class="form-control-static  margin-right">-->
                                <!--<img class="margin-right" src="__STATIC__/admin/img/u5339.png">-->
                            <!--</span>-->
							<!--<span class="form-control-static zhushi margin-right">-->
								<!--<span style="font-size: 18px">-->
									<!--物流配送-->
								<!--</span>-->
								<!--</br>-->
								<!--由第三方快递公司或商家完成商品配送服务-->
							<!--</span>-->
						<!--</div>-->

						<div class="row">
							<div class="form-group">
								<label class="col-lg-2 col-xs-4 control-label" style="margin-top: 20px"> <span class="required"> * </span>是否启用：</label>
								<div class=" col-lg-4 col-xs-3" style="margin-top: 20px">
									<div class="relative">
										<label class="radio-inline">
											<input class="is_enable" type="radio" name="is_enable" value="1" {:isset($getType) && $getType->status == 1 ? "checked":""} />
											是
										</label>
										<label class="radio-inline">
											<input class="is_enable" type="radio" name="is_enable" value="0" {:isset($getType) && $getType->status == 0 ? "checked":""} />
											否</label>
									</div>
								</div>
							</div>
						</div>

						<div class="row">
							<div class="form-group">
								<label class="col-lg-2 col-xs-4 control-label"> <span class="required"> * </span>配送方式：</label>
								<div class=" col-lg-4 col-xs-3">
									<div class="relative">
										<label class="radio-inline">
											<input class="deliverMethod" type="radio" name="deliverMethod" value="1" {:isset($getType)&& $getType->deliverMethod == 1 ? "checked" : ""} />
											商家直送
										</label>
										<label class="radio-inline">
											<input class="deliverMethod" type="radio" name="deliverMethod" value="0" {:isset($getType) && $getType->deliverMethod == 0 ? "checked" : "" }  />
											物流配送
										</label>

										<label class="radio-inline">
											<input class="deliverMethod" type="radio" name="deliverMethod" value="2" {:isset($getType)&& $getType->deliverMethod == 2 ? "checked" : "" } />
											同城快递（达达）
										</label>
									</div>
								</div>
							</div>
						</div>
						<!--***********************物流运费配置********************-->
						<form id="logistics-form" class="logistics hidden" method="post">
							<div class="prow">
								<div class="form-group">
									<label class="col-lg-2 col-xs-4 control-label"> <span class="required">   * </span>打包费：</label>
									<div class=" col-md-10 form-inline">
										<input class="logisticalPackingCharge  form-control margin-left" style="width: 80px" type="text" id="logisticalPackingCharge" value="{:isset($logisticalResult) ? $logisticalResult->packingCharge:'' }" name="logisticalPackingCharge"/>

										<span class="margin-left">
											元/件
										</span>
									</div>
								</div>

								<!--************************商户统一物流费用***********************-->
								<div class="unified">
									<div class="row">
										<div class="form-group">
											<label class="col-lg-2 col-xs-4 control-label"> <span class="required">   * </span>配送费用：</label>
											<div class=" col-md-10 form-inline">
												<label class="radio-inline">
													<input class="freight_type" type="radio" name="freight_type" value="0" {:isset($logisticalResult) && $logisticalResult->freight_type == 0 ? 'checked':'' } />
													<span class="margin-left">所有订单统一运费</span>
												</label>
											</div>
										</div>
									</div>

									<div class="row">
										<div class="form-group">
											<label class="col-lg-2 col-xs-4 control-label"> </label>
											<div class=" col-md-10 form-inline">
												<label class="radio-inline">
													<input class="unifiedmoney form-control margin-left" type="text" style="width: 80px" name="unifiedmoney" value="{:isset($logisticalRrule) && $logisticalResult->freight_type == 0 ? $logisticalRrule->unifiedmoney:'' }" />
													<span class="margin-left">
														元
													</span>
												</label>
											</div>
										</div>
									</div>
								</div>
								<!--***********************************************************-->


								<!--**************************商户按件数计算运费********************************-->
								<div class="piece">
									<div class="row">
										<div class="form-group">
											<label class="col-lg-2 col-xs-4 control-label"> </label>
											<div class=" col-md-10 form-inline">
												<label class="radio-inline">
													<input class="freight_type" type="radio" name="freight_type" value="1" {:isset($logisticalResult) && $logisticalResult->freight_type == 1 ? 'checked':'' } />
													<span class="margin-left">按件数计算运费</span>
												</label>
											</div>
										</div>

										<div class="form-group">
											<label class="col-lg-2 col-xs-4 control-label"></label>
											<div class="col-md-10 form-inline">
												<label class="radio-inline">
												<span>
													首
													<input class="first_num form-control margin-left" type="text" style="width: 80px" name="first_num" value="{:isset($logisticalRrule) && $logisticalResult->freight_type == 1 ? $logisticalRrule->first_num:'' }" />
													<span class="margin-left">
														件
													</span>
													<span class="margin-left">
														运费	<input class="first_money form-control margin-left" type="text" style="width: 80px" name="first_money" value="{:isset($logisticalRrule) && $logisticalResult->freight_type == 1 ? $logisticalRrule->first_money:'' }" />
														<span class="margin-left">元</span>
													</span>
												</span>
													<span class="margin-left">
													续
													<input class="continued_num form-control margin-left" type="text" style="width: 80px" name="continued_num" value="{:isset($logisticalRrule) && $logisticalResult->freight_type == 1 ? $logisticalRrule->continued_num:'' }" />
													<span class="margin-left">
														件
													</span>
													<span class="margin-left">
														续费	<input class="continued_money form-control margin-left" type="text" style="width: 80px" name="continued_money" value="{:isset($logisticalRrule) && $logisticalResult->freight_type == 1 ? $logisticalRrule->continued_money:'' }" />
														<span class="margin-left">元</span>
													</span>
												</span>
												</label>
											</div>
										</div>
									</div>
								</div>
								<!--***************************************************************************-->


								<!--********************************商户按重量计算运费*********************************-->
								<div class="kg">
									<div class="row">
										<div class="form-group">
											<label class="col-lg-2 col-xs-4 control-label"> </label>
											<div class=" col-md-10 form-inline">
												<label class="radio-inline">
													<input class="freight_type" type="radio" name="freight_type" value="2"  {:isset($logisticalResult) && $logisticalResult->freight_type == 2 ? 'checked':'' }/>
													<span class="margin-left">按重量（kg）计算运费</span>
												</label>
											</div>
										</div>

										<div class="form-group">
											<label class="col-lg-2 col-xs-4 control-label"></label>
											<div class="col-md-10 form-inline">
												<label class="radio-inline">
												<span>
													首
													<input class="first_num form-control margin-left" type="text" style="width: 80px" name="first_num" value="{:isset($logisticalRrule) && $logisticalResult->freight_type == 2 ? $logisticalRrule->first_num:'' }" />
													<span class="margin-left">
														kg
													</span>
													<span class="margin-left">
														运费	<input class="first_money form-control margin-left" type="text" style="width: 80px" name="first_money" value="{:isset($logisticalRrule) && $logisticalResult->freight_type == 2 ? $logisticalRrule->first_money:'' }" />
														<span class="margin-left">元</span>
													</span>
												</span>
													<span class="margin-left">
													续
													<input class="continued_num form-control margin-left" type="text" style="width: 80px" name="continued_num" value="{:isset($logisticalRrule) && $logisticalResult->freight_type == 2 ? $logisticalRrule->continued_num:'' }" />
													<span class="margin-left">
														kg
													</span>
													<span class="margin-left">
														续费	<input class="continued_money form-control margin-left" type="text" style="width: 80px" name="continued_money" value="{:isset($logisticalRrule) && $logisticalResult->freight_type == 2 ? $logisticalRrule->continued_num:'' }" />
														<span class="margin-left">元</span>
													</span>
												</span>
												</label>
											</div>
										</div>
									</div>
								</div>
								<!--************************************************************************-->
							</div>
						</form>
						<!--********************************************************-->


						<!--**************************商家直送********************************-->
						<form id="self-form" class="self hidden">
							<div class="row">
								<div class="form-group">
									<label class="col-lg-2 col-xs-4 control-label"> <span class="required">   * </span>配送费用：</label>
									<div class=" col-md-10 form-inline">
										<span class="  ">订单起送价</span>
										<input class="orderStartingPrice  form-control margin-left" id="orderStartingPrice" value="{:isset($orderStartingPrice)?$orderStartingPrice:''}" type="text" name="orderStartingPrice"/>
										<span>元</span>
									</div>
								</div>
							</div>

							<div class="row">
								<div class="form-group">
									<label class="col-lg-2 col-xs-4 control-label"> </label>
									<div class=" col-md-10 form-inline">
										<span class="  ">运费 <span class=""> 配送距离 ≤ 1km </span> </span><input class="orderStartingPrice  form-control margin-left" id="freight" value="{:isset($freight)?$freight:''}" type="text" name="freight"/><span>元</span>

									</div>
								</div>
							</div>

							<div class="row">
								<div class="form-group">
									<label class="col-lg-2 col-xs-4 control-label"> </label>
									<div class=" col-md-10 form-inline">

										<span class="  ">打包费用</span><input class="orderStartingPrice  form-control margin-left" type="text" id="packingCharge" value="{:isset($packingCharge)?$packingCharge:''}" name="packingCharge"/><span>元</span>

									</div>
								</div>
							</div>

							<div class="row">
								<div class="form-group">
									<label class="col-lg-2 col-xs-4 control-label"> <span class="required">   * </span> 距离加价：</label>
									<div class=" col-md-10 form-inline">
										<span class="col-md-3">1km ＜ 配送距离 ≤ 3km</span><span class="">加价</span>
										<input class="orderStartingPrice  form-control margin-left" type="text" data-param="1_3" id="distanceIncrease_1_3" value="{:isset($distanceIncrease_1_3)?$distanceIncrease_1_3:''}" name="distanceIncrease_1_3"/>
										<span>元</span>
									</div>
								</div>
							</div>

							<div class="row">
								<div class="form-group">
									<label class="col-lg-2 col-xs-4 control-label"> </label>
									<div class=" col-md-10 form-inline">
											<span class="col-md-3">
												3km ＜ 配送距离 ≤ 5km</span><span class="">加价</span>
										<input class="orderStartingPrice  form-control margin-left" type="text" data-param="3_5" id="distanceIncrease_3_5" value="{:isset($distanceIncrease_3_5)?$distanceIncrease_3_5:''}" name="distanceIncrease_3_5"/>
										<span>元</span>
									</div>
								</div>
							</div>

							<div class="row">
								<div class="form-group">
									<label class="col-lg-2 col-xs-4 control-label"> <span class="required">   * </span> 重量加价：</label>
									<div class=" col-md-10 form-inline">
										<span class="col-md-3">商品重量 ≤ 1kg</span><span class="">加价</span>
										<input class="orderStartingPrice  form-control margin-left" type="text" data-param="1" id="weightIncrease_1" value="{:isset($weightIncrease_1)?$weightIncrease_1:''}" name="weightIncrease_1"/>
										<span>元</span>
									</div>
								</div>
							</div>

							<div class="row">
								<div class="form-group">
									<label class="col-lg-2 col-xs-4 control-label"> </label>
									<div class=" col-md-10 form-inline">
										<span class="col-md-3">1kg ＜ 商品重量 ≤ 5kg</span><span class="">每增1kg加价</span>
										<input class="orderStartingPrice  form-control margin-left" type="text" data-param="1_5" id="weightIncrease_1_5" value="{:isset($weightIncrease_1_5)?$weightIncrease_1_5:''}" name="weightIncrease_1_5"/>
										<span>元</span>
									</div>
								</div>
							</div>

							<div class="row">
								<div class="form-group">
									<label class="col-lg-2 col-xs-4 control-label"> </label>
									<div class=" col-md-10 form-inline">
										<span class="col-md-3">5kg ＜ 商品重量 ≤ 10kg</span><span class="">每增5kg加价</span>
										<input class="orderStartingPrice  form-control margin-left" type="text" data-param="5_10" id="weightIncrease_5_10" value="{:isset($weightIncrease_5_10)?$weightIncrease_5_10:''}" name="weightIncrease_5_10"/>
										<span>元</span>
									</div>
								</div>
							</div>

							<div class="row">
								<div class="form-group">
									<label class="col-lg-2 col-xs-4 control-label"> <span class="required">   * </span>夜间加价：</label>
									<div class=" col-md-10 form-inline">
										<span class="">22:00 ~ 08:00</span>
										<span class="">加价</span>
										<input class="orderStartingPrice  form-control margin-left" type="text" data-param="22_08" id="nocturnalPriceIncrease_22_08" value="{:isset($nocturnalPriceIncrease_22_08)?$nocturnalPriceIncrease_22_08:''}" name="nocturnalPriceIncrease_22_08"/>
										<span>元</span>
									</div>
								</div>
							</div>
						</form>
						<hr />

						<div class="form-actions">
							<div class="row">
								<div class="col-md-12">
									<div class="form-group">
										<label class="col-md-3 control-label"></label>
										<div class="col-md-9">
											<button type="button" class="btn btn-primary" id="logistics">
												保存 <i class="fa fa-floppy-o"></i>
											</button>
											<button type="button" class="btn btn-default" onclick="history.go(-1);">
												返回 <i class="fa fa-mail-forward"></i>
											</button>
											<div class="help-block " style="color:red"></div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
{/block}

{block name="pagescript"}
<script>
    $(function() {
        var $deliverMethodDate = "{$deliverMethod}";
        var deliverMethod_0 = 0;//配送方式   0=物流配送  1=自行配送 2=达达配送 3=到店自取
        var deliverMethod_1 = 1;
        var deliverMethod_2 = 2;

        var deliverMethod = "{:isset($getType)?$getType->deliverMethod:''}";

        if(deliverMethod !=""){
            if (deliverMethod == deliverMethod_1) {
                $(".self").removeClass("hidden");
                $(".logistics").addClass("hidden")
            } else if(deliverMethod == deliverMethod_0){
                $(".self").addClass("hidden");
                $(".logistics").removeClass("hidden")
            }else {
                $(".self").addClass("hidden");
                $(".logistics").addClass("hidden")
            }
        }

        var obj = {};

        //物流配送费用操作
        $(".freight_type").click(function () {
            $(".freight_type").attr("checked",false);
            $(this).attr("checked",true);
            $(this).prop("checked", true);
            var $freight_type_value = $("input[name='freight_type']:checked").val();
            //存储运费类型
            $.data(obj,"freight_type",$freight_type_value);
        });

        var $logistics_type_id = '{$logistics_type_id}';

        // 保存
        $("#logistics").click(function () {
            var $deliverMethodValue = $("input[name='deliverMethod']:checked").val();

            var deliverMethod = $('input[name=deliverMethod]:checked').val();
            var isOpen = $('input[name=is_enable]:checked').val();
            if(isOpen == 0) {  //关闭操作
            	closeEnable();
            	return;
            }
            if (deliverMethod == deliverMethod_1) {   //商家直送
                var _data = $("#self-form").serializeObject();

                if(!mdTool.validate(_data.orderStartingPrice,'two') || _data.orderStartingPrice == 0){
                    mdTool.showMessage('订单起送价应大于0，且小数点后只有两位');
                    $("#orderStartingPrice").focus();
                    return false;
                }
                if(!mdTool.validate(_data.freight,'two') || _data.freight == 0){
                    mdTool.showMessage('运费应大于0，且小数点后只有两位');
                    $("#freight").focus();
                    return false;
                }
                if(!mdTool.validate(_data.packingCharge,'two') || _data.packingCharge == 0){
                    mdTool.showMessage('打包费用应大于0，且小数点后只有两位');
                    $("#packingCharge").focus();
                    return false;
                }
                if(!mdTool.validate(_data.distanceIncrease_1_3,'two') || _data.distanceIncrease_1_3 == 0){
                    mdTool.showMessage('距离加价应大于0，且小数点后只有两位');
                    $("#distanceIncrease_1_3").focus();
                    return false;
                }
                if(!mdTool.validate(_data.distanceIncrease_3_5,'two') || _data.distanceIncrease_3_5 == 0){
                    mdTool.showMessage('距离加价应大于0，且小数点后只有两位');
                    $("#distanceIncrease_3_5").focus();
                    return false;
                }
                if(!mdTool.validate(_data.weightIncrease_1,'two') || _data.weightIncrease_1 == 0){
                    mdTool.showMessage('重量加价应大于0，且小数点后只有两位');
                    $("#weightIncrease_1").focus();
                    return false;
                }
                if(!mdTool.validate(_data.weightIncrease_1_5,'two') || _data.weightIncrease_1_5 == 0){
                    mdTool.showMessage('重量加价应大于0，且小数点后只有两位');
                    $("#weightIncrease_1_5").focus();
                    return false;
                }
                if(!mdTool.validate(_data.weightIncrease_5_10,'two') || _data.weightIncrease_5_10 == 0){
                    mdTool.showMessage('重量加价应大于0，且小数点后只有两位');
                    $("#weightIncrease_5_10").focus();
                    return false;
                }
                if(!mdTool.validate(_data.nocturnalPriceIncrease_22_08,'two') || _data.nocturnalPriceIncrease_22_08 == 0){
                    mdTool.showMessage('夜间加价应大于0，且小数点后只有两位');
                    $("#nocturnalPriceIncrease_22_08").focus();
                    return false;
                }
            } else if(deliverMethod == deliverMethod_0){   //物流配送
                var _data = $("#logistics-form").serializeObject();

                if(!mdTool.validate(_data.logisticalPackingCharge,'two') || _data.logisticalPackingCharge == 0){
                    mdTool.showMessage('打包费应大于0，且小数点后只有两位');
                    $("#logisticalPackingCharge").focus();
                    return false;
                }

                var freight_type = $("input[name='freight_type']:checked").val();
                if(freight_type == 1){
                    var first_num = $(".piece").find(".first_num").val();
                    var first_money = $(".piece").find(".first_money").val();
                    var continued_num = $(".piece").find(".continued_num").val();
                    var continued_money = $(".piece").find(".continued_money").val();

                    if(!mdTool.validate(first_num,'num')){
                        mdTool.showMessage('件数为非零的正整数');
                        $(".piece").find(".first_num").focus();
                        return false;
                    }
                    if(!mdTool.validate(first_money,'two') || first_money == 0){
                        mdTool.showMessage('运费应大于0，且小数点后只有两位');
                        $(".piece").find(".first_money").focus();
                        return false;
                    }
                    if(!mdTool.validate(continued_num,'num')){
                        mdTool.showMessage('件数为非零的正整数');
                        $(".piece").find(".continued_num").focus();
                        return false;
                    }
                    if(!mdTool.validate(continued_money,'two') || continued_money == 0){
                        mdTool.showMessage('续费应大于0，且小数点后只有两位');
                        $(".piece").find(".continued_money").focus();
                        return false;
                    }
				}else if(freight_type == 2){
                    var first_num = $(".kg").find(".first_num").val();
                    var first_money = $(".kg").find(".first_money").val();
                    var continued_num = $(".kg").find(".continued_num").val();
                    var continued_money = $(".kg").find(".continued_money").val();

                    if(!mdTool.validate(first_num,'two') || first_num == 0){
                        mdTool.showMessage('重量应大于0，且小数点后只有两位');
                        $(".kg").find(".first_num").focus();
                        return false;
                    }
                    if(!mdTool.validate(first_money,'two') || first_money == 0){
                        mdTool.showMessage('续费应大于0，且小数点后只有两位');
                        $(".kg").find(".first_money").focus();
                        return false;
                    }
                    if(!mdTool.validate(continued_num,'two') || continued_num == 0){
                        mdTool.showMessage('重量应大于0，且小数点后只有两位');
                        $(".kg").find(".continued_num").focus();
                        return false;
                    }
                    if(!mdTool.validate(continued_money,'two') || continued_money == 0){
                        mdTool.showMessage('续费应大于0，且小数点后只有两位');
                        $(".kg").find(".continued_money").focus();
                        return false;
                    }
				}else{
                    if(!mdTool.validate(_data.unifiedmoney,'two') || _data.unifiedmoney == 0){
                        mdTool.showMessage('统一运费应大于0，且小数点后只有两位');
                        $(".unifiedmoney").focus();
                        return false;
                    }
				}
            } else {
                //
            }
            mdTool.showMessage('');

            if ($deliverMethodValue == deliverMethod_1 || $deliverMethodValue == deliverMethod_2) {
                //商家直送数据保存
                addLogistics();
            } else {
                addLogistical();
            }
        });

        $(".is_enable").click(function () {
            $(".is_enable").removeAttr("checked");
            $(this).attr("checked", true);
            $(this).prop("checked", true);
        });

        $(".deliverMethod").click(function () {
            $(".deliverMethod").removeAttr("checked");
            $(this).attr("checked", true);
            $(this).prop("checked", true);
            var $deliverMethodValue = $("input[name='deliverMethod']:checked").val();
            if ($deliverMethodValue == deliverMethod_1) {
                $(".self").removeClass("hidden");
                $(".logistics").addClass("hidden")
            } else if($deliverMethodValue == deliverMethod_0){
                $(".self").addClass("hidden");
                $(".logistics").removeClass("hidden")
            }else {
                $(".self").addClass("hidden");
                $(".logistics").addClass("hidden")
            }
        })
    });


    var freight_type_0 = 0;
    var freight_type_1 = 1;
    var freight_type_2 = 2;

    function freight_type_sitting(freight_type) {
        //统一运费
        if(freight_type == freight_type_0){                                     //获取统一运费
            var unifiedmoney = $(".unified").find('.unifiedmoney').val();
            var param = {
                freight_type:freight_type,
                unifiedmoney:unifiedmoney
            };
            return param;
        }else if(freight_type == freight_type_1 ){                               //按件数计算运费
            var first_money = $(".piece").find(".first_money").val();
            var first_num = $(".piece").find(".first_num").val();
            var continued_num = $(".piece").find(".continued_num").val();
            var continued_money = $(".piece").find(".continued_money").val();
            var param = {
                freight_type:freight_type,
                first_money:first_money,
                first_num:first_num,
                continued_num:continued_num,
                continued_money:continued_money
            };
            return param;
        }else if(freight_type == freight_type_2){
            var first_money = $(".kg").find(".first_money").val();
            var first_num = $(".kg").find(".first_num").val();
            var continued_num = $(".kg").find(".continued_num").val();
            var continued_money = $(".kg").find(".continued_money").val();
            var param = {
                freight_type:freight_type,
                first_money:first_money,
                first_num:first_num,
                continued_num:continued_num,
                continued_money:continued_money
            };
            return param;
        }else {                                                                   //按重量计算运费
            layer.msg("物流费设置类型不正确",{icon: 5, time: 1000});
        }
    }

    function addLogistical() {
        var $logistics_type_id = '{$logistics_type_id}';
        var logisticalId = "{:isset($logisticalId)?$logisticalId:''}";
        //运费
        var logisticalPackingCharge = $("#logisticalPackingCharge").val();

        var freight_type = $("input[name='freight_type']:checked").val();
        var param = freight_type_sitting(freight_type);

        param.packingCharge = logisticalPackingCharge; //配送费

        var is_enable = $("input[name='is_enable']:checked").val();
        param.status = is_enable;
        var $deliverMethodValue = $("input[name='deliverMethod']:checked").val();
        param.deliverMethod = $deliverMethodValue;
        param.logistics_type_id =$logistics_type_id;
        param.logisticalId = logisticalId;

        var url = "/admin/Logistical/settingLogistical";
        $.ajax({
            type: 'POST',
            url: url,
            data: param,
            dataType: 'json',
            success: function (data) {
                if(data.status == 0){
                    layer.msg(data.message, {icon: 5, time: 1000});
                }else{
                    layer.msg(data.message, {icon:6, time: 1000});
                    window.location.reload();
                }
            },
            error: function (data) {
                console.log(data.msg);
            },
        });
    }

    function closeEnable() {   //关闭物流配送
    	var url = "{:url('admin/Logistics/closeStatus')}";
        $.ajax({
            type: 'POST',
            url: url,
            data: {'id':"{$logistics_type_id}"},
            dataType: 'json',
            success: function (data) {
                if(data.status == 1){  //成功
                    layer.msg(data.message);
                    window.location.reload();
                }else{
                    layer.msg(data.message);
                }
            },
            error: function (data) {
                console.log(data.msg);
            },
        });
    }


    /**
     * 商家直送数据保存
     */
    function addLogistics() {
        var url = "/admin/Logistics/ajax_Add_Or_update_logistics";
        //is_enable ,                     //是否启用
        // orderStartingPrice,           //订单起送价格
        //freight						 //物流
        // packingCharge,                //打包费
        // distanceIncrease_0_5,        //距离加价0kg-5kg
        // distanceIncrease_2_10,       //距离加价2kg-10kg
        // distanceIncrease_10_50,      //距离加价10kg-50kg
        // nocturnalPriceIncrease_22_24,  //夜间加价22:00-24:00
        // nocturnalPriceIncrease_00_07   //夜间加价00:00-07:00

        var $logistics_type_id = '{$logistics_type_id}';
        var is_enable = $("input[name='is_enable']:checked").val();
        var orderStartingPrice = $('#orderStartingPrice').val();
        var freight = $('#freight').val();
        var packingCharge = $('#packingCharge').val();

        //重量加价
        var weightIncrease_1        =    $('#weightIncrease_1').attr("data-param");
        var weightIncrease_1_val    =    $('#weightIncrease_1').val()*100;
        var weightIncrease_1_5     	=    $('#weightIncrease_1_5').attr("data-param");
        var weightIncrease_1_5_val  =    $('#weightIncrease_1_5').val()*100;
        var weightIncrease_5_10     =    $('#weightIncrease_5_10').attr("data-param");
        var weightIncrease_5_10_val =    $('#weightIncrease_5_10').val()*100;

        var $weightIncrease = {weightIncrease_1:weightIncrease_1,weightIncrease_1_val:weightIncrease_1_val,weightIncrease_1_5:weightIncrease_1_5,weightIncrease_1_5_val:weightIncrease_1_5_val,weightIncrease_5_10:weightIncrease_5_10,weightIncrease_5_10_val:weightIncrease_5_10_val}
        $weightIncrease = JSON.stringify($weightIncrease)

        // 夜间加价
        var nocturnalPriceIncrease_22_08_val = $('#nocturnalPriceIncrease_22_08').val()*100;
        var nocturnalPriceIncrease_22_08 = $('#nocturnalPriceIncrease_22_08').attr("data-param");
        var nocturnalPriceIncrease = {nocturnalPriceIncrease_22_08:nocturnalPriceIncrease_22_08,nocturnalPriceIncrease_22_08_val:nocturnalPriceIncrease_22_08_val}
        nocturnalPriceIncrease = JSON.stringify(nocturnalPriceIncrease);

        //距离加价
        var distanceIncrease_1_3   =   $('#distanceIncrease_1_3').attr("data-param");
        var distanceIncrease_3_5   =   $('#distanceIncrease_3_5').attr("data-param");

        var distanceIncrease_1_3_val   =   $('#distanceIncrease_1_3').val()*100;
        var distanceIncrease_3_5_val   =   $('#distanceIncrease_3_5').val()*100;

        var $distanceIncrease = {distanceIncrease_1_3:distanceIncrease_1_3,distanceIncrease_1_3_val:distanceIncrease_1_3_val,distanceIncrease_3_5:distanceIncrease_3_5,distanceIncrease_3_5_val:distanceIncrease_3_5_val}
        $distanceIncrease = JSON.stringify($distanceIncrease)

        var $deliverMethodValue    =   $("input[name='deliverMethod']:checked").val();

        var params = {
            is_enable: is_enable,
            orderStartingPrice: orderStartingPrice,
            freight: freight,
            packingCharge: packingCharge,
            weightIncrease:$weightIncrease,
            distanceIncrease: $distanceIncrease,
            nocturnalPriceIncrease: nocturnalPriceIncrease,
            tdtTypeId: $logistics_type_id,
            deliverMethod: $deliverMethodValue
        };

        $.ajax({
            type: 'POST',
            url: url,
            data: params,
            dataType: 'json',
            success: function (data) {
                layer.msg(data.message, {icon: 6, time: 1000});
                window.location.reload();
            },
            error: function (data) {
                console.log(data.msg);
            },
        });
    }
</script>
{/block}